package adv.i31.robot;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

public class VertexBuffer {

	/** How many elements per vertex. */
	private final int mStrideBytes = 3 * mBytesPerFloat;

	/** Offset of the position data. */
	private final int mPositionOffset = 0;

	/**
	 * Size of the position data in elements. NOT the number of vertices in the
	 * buffer
	 */
	private final int mPositionDataSize = 3;

	private static final int mBytesPerFloat = Float.SIZE / 8;

	private int mNumVertices;

	public int getNumVertices() {
		return mNumVertices;
	}

	private FloatBuffer mFloatBuffer;

	public VertexBuffer() {
	}

	public VertexBuffer(float[] matrix4x4) {
		this();

		mNumVertices = matrix4x4.length / 3;

		// Initialize the buffers.
		mFloatBuffer = ByteBuffer.allocateDirect(matrix4x4.length * mBytesPerFloat)
				.order(ByteOrder.nativeOrder()).asFloatBuffer();

		mFloatBuffer.put(matrix4x4).position(0);

		// Pass in the position information
		mFloatBuffer.position(mPositionOffset);
	}

	public int getmStrideBytes() {
		return mStrideBytes;
	}

	public int getmPositionOffset() {
		return mPositionOffset;
	}

	public int getmPositionDataSize() {
		return mPositionDataSize;
	}

	public static int getMbytesperfloat() {
		return mBytesPerFloat;
	}

	public FloatBuffer getmFloatBuffer() {
		return mFloatBuffer;
	}

}
